package susebs.pb.travel_server.service.impl;

import susebs.pb.travel_server.entity.LandmarkPackage;
import susebs.pb.travel_server.dao.LandmarkPackageDao;
import susebs.pb.travel_server.entity.Landmarks;
import susebs.pb.travel_server.service.LandmarkPackageService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import susebs.pb.travel_server.service.LandmarksService;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * (LandmarkPackage)表服务实现类
 *
 * @author makejava
 * @since 2024-02-12 16:56:22
 */
@Service("landmarkPackageService")
public class LandmarkPackageServiceImpl implements LandmarkPackageService {
    @Resource
    private LandmarkPackageDao landmarkPackageDao;
    @Resource
    private LandmarksService landmarksService;

    /**
     * 通过ID查询单条数据
     *
     * @param lmId 主键
     * @return 实例对象
     */
    @Override
    public LandmarkPackage queryById(Long lmId) {
        return this.landmarkPackageDao.queryById(lmId);
    }

    /**
     * 分页查询
     *
     * @param landmarkPackage 筛选条件
     * @param pageRequest     分页对象
     * @return 查询结果
     */
    @Override
    public Page<LandmarkPackage> queryByPage(LandmarkPackage landmarkPackage, PageRequest pageRequest) {
        long total = this.landmarkPackageDao.count(landmarkPackage);
        return new PageImpl<>(this.landmarkPackageDao.queryAllByLimit(landmarkPackage, pageRequest), pageRequest, total);
    }

    /**
     * 套餐关联的实体id列表
     */
    @Override
    public ArrayList queryAll(Long pkId) {
        ArrayList<Long> res = new ArrayList<>();

        ArrayList<LandmarkPackage> list = landmarkPackageDao.queryAll(pkId);
        for (LandmarkPackage l:list) {
            res.add(l.getLmId());
        }

        return res;
    }


    @Override
    public ArrayList<Landmarks> queryByIds(ArrayList<Long> list) {
        ArrayList<Landmarks> res = new ArrayList<>();
        for (Long id:list) {
            Landmarks landmark = landmarksService.queryById(id);
            res.add(landmark);
        }
        return res;
    }

    /**
     * 新增数据
     *
     * @param landmarkPackage 实例对象
     * @return 实例对象
     */
    @Override
    public LandmarkPackage insert(LandmarkPackage landmarkPackage) {
        this.landmarkPackageDao.insert(landmarkPackage);
        return landmarkPackage;
    }

    /**
     * 修改数据
     *
     * @param landmarkPackage 实例对象
     * @return 实例对象
     */
    @Override
    public LandmarkPackage update(LandmarkPackage landmarkPackage) {
        this.landmarkPackageDao.update(landmarkPackage);
        return this.queryById(landmarkPackage.getLmId());
    }

    /**
     * 通过主键删除数据
     *
     * @param lmId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long lmId) {
        return this.landmarkPackageDao.deleteById(lmId) > 0;
    }
}
